package item.inkcloud.communityservice.controller;


import com.alibaba.fastjson.JSONObject;
import item.inkcloud.communityservice.entity.Article;
import item.inkcloud.communityservice.entity.Comment;
import item.inkcloud.communityservice.mapper.CommentMapper;
import item.inkcloud.communityservice.service.ArticleService;
import item.inkcloud.communityservice.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RequestMapping("/community")
@RestController
public class PublishController {

       @Autowired
       ArticleService articleService;

       @Autowired
       CommentService commentService;

       @RequestMapping("/publishArticle")
       HashMap publishArticle(@RequestBody JSONObject jsonPara, @RequestParam("userid") String userid){

              Article article =jsonPara.toJavaObject(Article.class);

              int status = articleService.publishArticle(article,userid);

              HashMap<String,Object> resultMap = new HashMap<>();

              resultMap.put("starus",status);


              return resultMap;


       }

       @RequestMapping("/publishComment")
       HashMap publishComment(@RequestBody JSONObject jsonPara,@RequestParam("userid")String userid){

              Comment comment = jsonPara.toJavaObject(Comment.class);

              int status = commentService.publishComment(comment,userid) ;

              HashMap<String,Object> resultMap = new HashMap<>();

              resultMap.put("status",status);

              return  resultMap;

       }



}

